package com.jf.blog.controller;

import com.jf.blog.form.comment.CommentForm;
import com.jf.blog.service.CommentService;
import com.jf.blog.util.ResultJson;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 评论表 前端控制器
 * </p>
 *
 * @author JF
 * @since 2025-06-20
 */
@RestController
@RequestMapping("/comment")
@Api(tags = "评论模块")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @PutMapping("/save")
    @ApiOperation("发表评论")
    public ResultJson save(@RequestBody CommentForm form) {
        commentService.save(form);
        return ResultJson.success();
    }

    @GetMapping("/page")
    @ApiOperation("分页筛选")
    public ResultJson getPage(@RequestParam(defaultValue = "1") @ApiParam(required = true) int page, @RequestParam(defaultValue = "5") @ApiParam(required = true) int limit, @RequestParam @ApiParam(required = true) int blogId) {
        return commentService.getPage(page, limit, blogId);
    }

    @PostMapping("/status/{commentId}")
    @ApiOperation("修改状态")
    public ResultJson status(@PathVariable int commentId) {
        commentService.status(commentId);
        return ResultJson.success();
    }

    @GetMapping("/info/{commentId}")
    @ApiOperation("评论详情")
    public ResultJson info(@PathVariable int commentId) {
        return ResultJson.success(commentService.getById(commentId));
    }

    @DeleteMapping("/delete")
    @ApiOperation("批量删除")
    public ResultJson delete(@RequestBody List<Integer> commentIds) {
        commentService.removeByIds(commentIds);
        return ResultJson.success();
    }

}
